

        var o = {
            name: "tuyouSDKwechat",
            SESSION_KEY: "TY_SZ_SESSION_STORAGE",
            ctor: function () {
                console.log("sdk ctor:", this.name);
            },
            decode: function (e) {
                return console.log("sdk decode data:"), Global.utils.decodeMessageTy(e);
            },
            login: function () {
                try {
                    var e = wx.getStorageSync("key_wx_uuid");
                    e || (e = function () {
                        for (var e = [], t = 0; t < 36; t++) e[t] = "0123456789abcdef".substr(Math.floor(16 * Math.random()), 1);
                        return e[14] = "4", e[19] = "0123456789abcdef".substr(3 & e[19] | 8, 1), e[8] = e[13] = e[18] = e[23] = "",
                            e.join("");
                    }(), wx.setStorageSync("key_wx_uuid", e)), console.log("sdk login", "uuid = " + e);
                } catch (e) {
                }
                this.wechatLogin();
            },
            wechatLogin: function () {
                console.log("wx login: wechatLogin");
                var e = this;
                wx.login({
                    success: function (t) {
                        if (console.log("wx login success, params:" + JSON.stringify(t)), t.code) {
                            var n = t.code;
                            e.checkWxSetting(n, !1);
                        } else console.log("Error: params.code == null"), e._showLoginFailAlert(0);
                    },
                    fail: function (t) {
                        console.log("params.code" + JSON.stringify(t)), e._showLoginFailAlert(1, t);
                    },
                    complete: function (e) {
                    }
                });
            },
            checkWxSetting: function (e, t) {
                var n = this;
                try {
                    wx.getSetting({
                        success: function (o) {
                            var i = o.authSetting;
                            !0 === i["scope.userInfo"] ? (console.log("用户已授权"), n.wxGetUserInfo(e, t)) : !1 === i["scope.userInfo"] ? (console.log("用户已拒绝授权"),
                                n.loginTuyooWithCode(null, null, e)) : (console.log("未询问过用户授权"), tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeAuthorizationStart, []),
                                wx.authorize({
                                    scope: "scope.userInfo",
                                    success: function () {
                                        tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeAuthorizationSuccess, []),
                                            tywx.NotificationCenter.trigger(tywx.EventType.START_AUTHORIZATION_SUCCESS), n.wxGetUserInfo(e, t);
                                    },
                                    fail: function () {
                                        tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeAuthorizationFailed, []),
                                            tywx.NotificationCenter.trigger(tywx.EventType.START_AUTHORIZATION_FAILED), n.loginTuyooWithCode(null, null, e);
                                    },
                                    complete: function () {
                                    }
                                }));
                        },
                        fail: function (t) {
                            console.error("wx.getSetting fail res:", t), n.loginTuyooWithCode(null, null, e);
                        }
                    });
                } catch (t) {
                    console.error("checkWxSetting e:", t), n.loginTuyooWithCode(null, null, e);
                }
            },
            wxGetUserInfo: function (e, t) {
                var n = this;
                wx.getUserInfo({
                    success: function (o) {
                        console.log("wx getUserInfo success, params:" + JSON.stringify(o));
                        var i = o.userInfo, a = i.nickName, r = i.avatarUrl, s = i.gender, l = (i.province,
                            i.city, i.country, o.signature), c = o.rawData;
                        Global.userProfile.setUserName(a), Global.userProfile.setUserPic(r), Global.userProfile.setUserSex(s),
                            l && c ? t ? n.loginTuyooWithSession(l, c, e) : n.loginTuyooWithCode(l, c, e) : (console.log("Error: signature && rawData == null"),
                                n.loginTuyooWithCode(null, null, e));
                    },
                    fail: function (t) {
                        console.log("wx getUserInfo fail, res:" + JSON.stringify(t)), n.loginTuyooWithCode(null, null, e);
                    }
                });
            },
            loginTuyooWithCode: function (e, t, n) {
                var o = this, i = wx.getStorageSync("key_wx_uuid"), a = {
                    appId: Global.config.appId,
                    clientId: Global.config.CLIENTID,
                    loginFlag: 0,
                    imei: "null",
                    uuid: i,
                    snsId: "wxapp:" + n,
                    wxAppId: Global.config.wxAppId,
                    nickName: Global.userProfile.getUserName(),
                    avatarUrl: Global.userProfile.getUserPic(),
                    gender: Global.userProfile.getUserSex(),
                    rawData: t,
                    signature: e
                };
                console.log("loginTuyooWithCode: tuyoo login requestData:" + JSON.stringify(a)),
                    wx.request({
                        url: Global.config.loginUrl + "open/v6/user/LoginBySnsIdNoVerify?",
                        method: "POST",
                        header: {
                            "content-type": "application/x-www-form-urlencoded"
                        },
                        data: a,
                        success: function (e) {
                            console.log("loginTuyooWithCode, tuyoo server login success, params:" + JSON.stringify(e));
                            var t = e.data;
                            if (t.error && 0 != t.error.code) console.log("Error: params.data == null ..."); else {
                                var n = t.result;
                                Global.userProfile.setUserId(n.userId), Global.userProfile.authorCode = n.authorCode,
                                    console.log("userId:" + Global.userProfile.getUserId() + " userName:" + Global.userProfile.getUserName() + " userPic:" + Global.userProfile.getUserPic());
                                var i = n.token;
                                console.log("token:" + i), wx.setStorage({
                                    key: o.SESSION_KEY,
                                    data: i
                                });
                                var a, r = n.tcpsrv.ip, s = n.tcpsrv.wsport || n.tcpsrv.port;
                                console.log("loginTuyooWithCode success", "ip:" + r + " port:" + s), a = "wss://" + r + ":" + s.toString() + "/",
                                    console.log("loginTuyooWithCode success", "webSocketUrl:" + a), Global.config.host = a,
                                    Global.notificationCenter.emit(Global.eventName.MSG_LOGIN_SUCCESS, t);
                            }
                        },
                        fail: function (e) {
                            console.log("loginTuyooWithCode: tuyoo login fail, params:" + JSON.stringify(e)),
                                o._showLoginFailAlert(4, e);
                        },
                        complete: function (e) {
                        }
                    });
            },
            loginTuyooWithSession: function (e, t, n) {
                var o = this, i = (wx.getStorageSync("key_wx_uuid"), {
                    appId: Global.config.appId,
                    clientId: Global.config.CLIENTID,
                    snsId: n,
                    deviceName: "wechatGame"
                });
                console.log("loginTuyooWithCode: tuyoo login requestData:" + JSON.stringify(i)),
                    wx.request({
                        url: Global.config.loginUrl + "open/v3/user/processSnsIdNew?",
                        data: i,
                        success: function (e) {
                            console.log("sdk loginTuyooWithSession", "success params = " + JSON.stringify(e));
                        },
                        fail: function (e) {
                            console.log("loginTuyooWithCode: tuyoo login fail, params:" + JSON.stringify(e)),
                                o._showLoginFailAlert(4, e);
                        },
                        complete: function (e) {
                        }
                    });
            },
            showShareMenu: function () {
                if (cc.sys.platform == cc.sys.WECHAT_GAME) {
                    var e = this;
                    cc.log("showShareMenu"), wx.showShareMenu({
                        withShareTicket: !1,
                        success: function (t) {
                            console.log("share: tuyoo showShareMenu success, params:" + JSON.stringify(t)),
                                canvas.toTempFilePath({
                                    x: 0,
                                    y: 0,
                                    width: 1280,
                                    height: 720,
                                    destWidth: 360,
                                    destHeight: 288,
                                    success: function (t) {
                                        e.tempFilePath = e.tempFilePath || t.tempFilePath, wx.onShareAppMessage(function () {
                                            var t = tywx.ShareInterface.getOnShareAppMessageInfo();
                                            return null == t && (t = tywx.ShareInterface.getRandomOnShareAppMessageInfo(Global.config.sharePointId.hallShare)),
                                                tywx.BiLog.clickStat(tywx.clickStatEventType.clickStatEventTypeUserShare, [t.sharePointId, 1, t.shareSchemeId]),
                                                t.title = tywx.GameFeature._replaceKeyContent(t.title), {
                                                title: t.title || "途游四川麻将转发",
                                                imageUrl: t.imageUrl || e.tempFilePath,
                                                success: function (t) {
                                                    console.log("share: tuyoo onShareAppMessage success, res:" + JSON.stringify(t), e.tempFilePath);
                                                },
                                                fail: function (e) {
                                                    console.log("share: tuyoo onShareAppMessage fail, params:" + JSON.stringify(e));
                                                }
                                            };
                                        });
                                    }
                                });
                        },
                        fail: function (e) {
                            console.log("share: tuyoo showShareMenu fail, params:" + JSON.stringify(e));
                        }
                    });
                }
            },
            shareWithConfig: function (e, t, n, o, i) {
                var a, r = Global.configCdn.getShareConf().keyConfig || {};
                a = "" == e.content ? null : e.content;
                var s, l = "";
                for (var c in r) switch (c) {
                    case "@key1@":
                        l = Global.tableModel.getCreateTableNo() + "", a && (a = a.replace(c, l));
                        break;

                    case "@key2@":
                        l = Global.utils.getFixString(Global.userProfile.getUserName(), 5), a && (a = a.replace(c, l));
                }
                s = "" == e.shareIcon ? null : Global.config.resUrl + "/share/" + e.shareIcon + ".jpg?md5=" + cc.sys.now(),
                    i ? this.dahuShare(a, i, t, n, o) : this.share(a, s, t, n, o);
            },
            share: function (e, t, n, o, i) {
                console.log("share: tuyoo share");
                var a = Global.utils.randomInt(0, Global.config.shareText.length - 1);
                e = e || Global.config.shareText[a], canvas.toTempFilePath({
                    x: 0,
                    y: 0,
                    width: 1280,
                    height: 720,
                    destWidth: 360,
                    destHeight: 288,
                    fileType: "jpg",
                    success: function (a) {
                        t || (t = a.tempFilePath), wx.shareAppMessage({
                            title: e,
                            imageUrl: t,
                            query: n,
                            success: function (e) {
                                console.log("share: tuyoo shareAppMessage success, params:" + JSON.stringify(e)),
                                o && o(e);
                            },
                            fail: function (e) {
                                console.log("share: tuyoo shareAppMessage fail, params:" + JSON.stringify(e)), i && i(e);
                            }
                        });
                    }
                });
            },
            dahuShare: function (e, t, n, o, i) {
                var a = cc.director.getWinSize().width / tywx.SystemInfo.wxSystemInfo.screenWidth, r = t.targetNode,
                    s = r.width, l = r.height;
                canvas.toTempFilePath({
                    x: 0,
                    y: 0,
                    width: s / a * 2,
                    height: l / a * 2,
                    destWidth: 500 / a * 2,
                    destHeight: 400 / a * 2,
                    fileType: "jpg",
                    success: function (t) {
                        console.log("dahu share: toTempFilePath success");
                        var a = t.tempFilePath;
                        console.log("dahu share: toTempFilePath success imagUrl = ", a), wx.shareAppMessage({
                            title: e,
                            imageUrl: a,
                            query: n,
                            success: function (e) {
                                console.log("dahu share: tuyoo shareAppMessage success, params:" + JSON.stringify(e)),
                                o && o(e);
                            },
                            fail: function (e) {
                                console.log("dahu share: tuyoo shareAppMessage fail, params:" + JSON.stringify(e)),
                                i && i(e);
                            }
                        });
                    },
                    fail: function (e) {
                        console.log("dahu share: toTempFilePath fail, params:" + JSON.stringify(e)), i && i(e);
                    }
                });
            },
            onGameShowHideStatus: function (e, t) {
                wx.onShow(function (t) {
                    if (console.log("wx.onShow result:", JSON.stringify(t), this.isHide), this.isHide) {
                        this.isHide = !1, Global.notificationCenter && Global.notificationCenter.start();
                        var n = t.scene;
                        if (Global.myLaunchOption = t, 1044 == n || 1007 == n || 1008 == n || 1036 == n) {
                            var o = t.shareTicket;
                            if (o && (Global.myLaunchOption.shareTicket = o), Global.query = t.query, Global.query.extraInfo && "string" == typeof Global.query.extraInfo) try {
                                Global.query.extraInfo = JSON.parse(Global.query.extraInfo), console.error("Global.query onShow:", Global.query);
                            } catch (e) {
                                console.error("exception:", e, Global.query.extraInfo);
                            }
                            Global.notificationCenter.emit(Global.eventName.MSG_UPDATE_QUERY);
                        }
                        e && e();
                    }
                }.bind(this)), wx.onHide(function () {
                    console.log("wx.onHide"), this.isHide || (this.isHide = !0, Global.notificationCenter && Global.notificationCenter.stop(),
                    t && t());
                }.bind(this));
            },
            _showLoginFailAlert: function (e, t, n) {
                if (!Global.UIPopupManager.getPopupCompByUrl("PopupPanel/PopupAlert")) {
                    var o = "";
                    o = "登录失败，请重新登录", o = n = void 0 == n ? o : n;
                    var i = Global.spriteAtlas.getOKSpf();
                    Global.utils.showReconnectAlert(o, "确定", i, function () {
                        console.log("----------重新登录--------- "), Global.netWork.closeAndReconnect(5);
                    });
                }
            },
            requestBILog: function (e, t) {
                wx.request({
                    url: e,
                    method: "POST",
                    data: t,
                    success: function (e) {
                    },
                    fail: function (e) {
                        console.log("requestBILog fail, params:" + JSON.stringify(e));
                    },
                    complete: function (e) {
                    }
                });
            },
            getSystemInfo: function () {
                console.log("getSystemInfo"), tywx.SystemInfo.wxSystemInfo = wx.getSystemInfoSync(),
                    wx.getNetworkType({
                        success: function (e) {
                            console.log("getNetworkType success, params:" + JSON.stringify(e)), tywx.StateInfo.networkType = e.networkType;
                        },
                        fail: function (e) {
                            console.log("getNetworkType fail, params:" + JSON.stringify(e));
                        }
                    });
            },
            checkForUpdate: function () {
                if ("function" == typeof wx.getUpdateManager) {
                    var e = wx.getUpdateManager();
                    e.onCheckForUpdate(function (e) {
                        console.log(e.hasUpdate);
                    }), e.onUpdateReady(function () {
                        var t = {
                            text: "发现新版本，是否马上更新。",
                            confirmText: "确定",
                            confirmSp: Global.spriteAtlas.getOKSpf(),
                            confirmCallback: function () {
                                console.log("----------马上更新--------- "), e.applyUpdate();
                            },
                            cancelText: "取消",
                            cancelSp: Global.spriteAtlas.getCancelSpf(),
                            cancelCallback: function () {
                                console.log("----------取消更新--------- ");
                            },
                            needCloseBtn: !1
                        };
                        Global.UIPopupManager.alert(t);
                    }), e.onUpdateFailed(function () {
                        console.log("update fail");
                    });
                }
            },
            exitGame: function () {
                try {
                    wx.exitMiniProgram({
                        success: function (e) {
                            console.log("exitMiniProgram success");
                        },
                        fail: function (e) {
                            console.log("openSexitMiniProgrametting fail");
                        }
                    });
                } catch (e) {
                    console.error("exitGame error:", e);
                }
            },
            showQRlink: function () {
                try {
                    var e = "http://10.1.1.18/QRcode.png";
                    wx.previewImage({
                        current: e,
                        urls: [e]
                    });
                } catch (e) {
                    console.error("showQRlink error:", e);
                }
            },
            recharge: function (e) {
                console.log("sdk recharge:", e);
                tywx.TuyooSDK.createOrder(e.prodId, e.prodPrice, e.prodName, 1, null, null, function () {
                    console.log(" createOrder successCallback"), Global.SetIsFirstRecharge(!0), Global.notificationCenter.emit(Global.eventName.MSH_SHOWFIRSTRECHARGE);
                }, function () {
                    console.log(" createOrder failCallback");
                });
            }
        };
        if (cc.sys.platform == cc.sys.WECHAT_GAME) try {
            wx.setEnableDebug({
                enableDebug: Global.config.isDebug
            }), wx.onError(function (e) {
                console.log("wechat onError message stack:", e.message, e.stack);
            }), wx.setPreferredFramesPerSecond(30), wx.setKeepScreenOn({
                keepScreenOn: !0,
                success: function () {
                    console.log("setKeepScreenOn success");
                },
                fail: function () {
                    console.log("setKeepScreenOn fail");
                }
            });
        } catch (e) {
            console.error("wx error:", e);
        }
         module.exports = o
